<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('commerce_merchant', function (Blueprint $table) {
            $table->comment('商户信息');
            $table->bigIncrements('id')->comment('主键ID');
            $table->unsignedBigInteger('spot_id')->nullable()->comment('所属点位ID');
            $table->string('merchant_name', 128)->comment('商户名称');
            $table->unsignedTinyInteger('merchant_type')->default(1)->comment('商户类型：1-个体户，2-企业，3-虚拟商户，4-合作社，5-政府单位');
            $table->string('legal_person', 32)->nullable()->comment('法人代表');
            $table->string('legal_person_phone', 32)->nullable()->comment('法人联系方式');
            $table->string('legal_person_id_card', 255)->nullable()->comment('法人身份证');
            $table->string('contact_person', 32)->nullable()->comment('商户联系人');
            $table->string('contact_phone', 32)->nullable()->comment('商户联系电话');
            $table->string('contact_email', 64)->nullable()->comment('联系邮箱');
            $table->string('address', 255)->nullable()->comment('商店地址');
            $table->text('business_scope')->nullable()->comment('经营范围');
            $table->time('open_time')->nullable()->comment('商户开门时间');
            $table->time('close_time')->nullable()->comment('商户关门时间');
            $table->decimal('registered_capital', 15, 2)->nullable()->comment('注册资本');
            $table->date('established_date')->nullable()->comment('成立日期');
            $table->string('business_license_url', 255)->nullable()->comment('营业执照照片');
            $table->string('business_license', 64)->nullable()->comment('营业执照号');
            $table->string('tax_id', 64)->nullable()->comment('税务登记号');
            $table->string('bank_name', 64)->nullable()->comment('开户银行');
            $table->string('bank_account', 64)->nullable()->comment('银行账号');
            $table->unsignedTinyInteger('status')->default(1)->comment('商户状态：1-正常营业，2-歇业，3-注销');
            $table->unsignedBigInteger('admin_id')->comment('管理员ID');
            $table->text('remark')->nullable()->comment('备注');
            $table->index('merchant_name', 'idx_merchant_name');
            $table->index('status', 'idx_status');
            $table->index('admin_id', 'idx_admin_id');
            $table->timestamps();
            $table->softDeletes();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('commerce_merchant');
    }
};